package geotransform.tools;

import java.util.*;
import geotransform.*;
import geotransform.coords.*;
import geotransform.datum.*;
import geotransform.ellipsoids.*;
import geotransform.transforms.*;


public class ElementoColeta {
	
	public Gdc_Coord_3d coordGEO;
	public Utm_Coord_3d coordUTM;
	public String gpsData, classe;
	
	public ElementoColeta(ArrayList<String> data) throws Exception{
		classe = data.get(0);
		gpsData = data.get(1);
		int nv=0;
		int lo = -1, hi = 0;
		String lat = new String("0000.00000");
		String lon = new String("0000.00000");
		char ss[] = gpsData.toCharArray();
		for(int i=0; i<ss.length; i++){
		    if(ss[i] == ','){
		        nv++;
		        lo = hi;
		        hi = i;
		    }
		    if(nv == 3){
		        lat = new String(ss,lo+1,hi-lo-1);
		    }
		    if(nv == 5){
		        lon = new String(ss,lo+1,hi-lo-1);
		    }
		}
		String latD = new String(lat.toCharArray(),0,2);
		String latM = new String(lat.toCharArray(),2,lat.length()-2);
		String lonD = new String(lon.toCharArray(),0,3);
		String lonM = new String(lon.toCharArray(),3,lon.length()-3);
		
		double latitudeD, latitudeM, longitudeD, longitudeM;
		latitudeD = Double.parseDouble(latD);
		latitudeM = Double.parseDouble(latM);
		longitudeD = Double.parseDouble(lonD);
		longitudeM = Double.parseDouble(lonM);
		
		coordGEO = new Gdc_Coord_3d((-(latitudeD + latitudeM/60)) ,(-(longitudeD + longitudeM/60)),0.0);
		coordUTM = ConvertCoordSystem.geoToUtm(ConvertDatum.WGS84toSAD69(coordGEO), "sad");
	}
	
	public Gdc_Coord_3d getCoordGeo(){
		return this.coordGEO;
	}
	
	public Utm_Coord_3d getCoordUTM(){
		return this.coordUTM;
	}
	
	public String toString(){
		return  String.format("%d",(int)(coordUTM.x*100))  + "*" + String.format("%d",(int)(coordUTM.y*100)) + "*" + this.classe + "*";
	}
}
